//define(function(require,exports){
	var shopApp = angular.module('shopApp');
	shopApp.config(function ($httpProvider) {
		$httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';
	    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
	    $httpProvider.defaults.transformRequest = [function(data) {
	        /**
	         * The workhorse; converts an object to x-www-form-urlencoded serialization.
	         * @param {Object} obj
	         * @return {String}
	         */
	        var param = function(obj) {
	            var query = '';
	            var name, value, fullSubName, subName, subValue, innerObj, i;
	            for (name in obj) {
	                value = obj[name];
	                if (value instanceof Array) {
	                    for (i = 0; i < value.length; ++i) {
	                        subValue = value[i];
	                        fullSubName = name + '[' + i + ']';
	                        innerObj = {};
	                        innerObj[fullSubName] = subValue;
	                        query += param(innerObj) + '&';
	                    }
	                } else if (value instanceof Object) {
	                    for (subName in value) {
	                        subValue = value[subName];
	                        fullSubName = name + '[' + subName + ']';
	                        innerObj = {};
	                        innerObj[fullSubName] = subValue;
	                        query += param(innerObj) + '&';
	                    }
	                } else if (value !== undefined && value !== null) {
	                    query += encodeURIComponent(name) + '='
	                            + encodeURIComponent(value) + '&';
	                }
	            }
	            return query.length ? query.substr(0, query.length - 1) : query;
	        };
	        return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
	    }];
	});
//	shopApp.filter("shopAppFilter",function(){   
//        return function(obj,args,args){       
//               //...执行业务逻辑代码        
//               return 处理后的对象;    
//         };
//	}); 
	shopApp.controller('AboutCtrl',["$rootScope","$scope","$http","$window","$routeParams","$location", function ($rootScope,$scope,$http,$window,$routeParams,$location) {
			//取得当前的shopId和名称
			$scope.shopId = $routeParams.cid ? $routeParams.cid :($window.localStorage.shopId?$window.localStorage.shopId:"0");
			if($routeParams.cid!==0 && !$window.localStorage.shopId){
				$window.localStorage.shopId = $routeParams.cid;
			}
			$scope.shopName = $routeParams.cname ? $routeParams.cname : "0";
			$scope.hasDish = false;
			
			//  /u/shop/get-shop-info.jhtm
//			$scope.shopId = 2286;
			$scope.shopId = 62;
			/**
			 * 获取店铺信息，包含店铺图片url
			 */
			$http.post(
                hpfbase.url+"/u/shop/get-shop-info.jhtm",
                {shopId:$scope.shopId}
			).success(function(ret){
				if(ret.statusCode){
					if(!ret.data) return ;
					$scope.hasDish = true;
					var shopsData = ret.data;
					var shopPhone = shopsData.phone;
					if(!shopPhone){
						shopPhone = shopsData.telephone;
					}
					$scope.shopPhone = shopPhone;
					$scope.logoUrls = new Array();
					var shopEnviImg = shopsData.shopEnviImg;
					if(shopEnviImg){
						var urlArray = shopEnviImg.split(",");
						var target = "itype=1";
						for(var index in urlArray){
							var url = urlArray[index];
							if(!url) continue ;
							var no = url.indexOf(target);
							if(no > 0){
								$scope.logoUrls.push(url);
								continue ;
							}
						}
					}
					$scope.dishList = shopsData.dishsItem;
					if($scope.dishList){
						var target = "itype=2";
						for(var i in $scope.dishList){
							$scope.dishList[i].imgUrls = new Array();
							var dish = $scope.dishList[i];
							var urls = dish.imgUrl;
							if(!urls) continue ;
							var urlArray = urls.split(",");
							$scope.dishList[i].imgUrls = urlArray;
//							for(var j in urlArray ){
//								var url = urlArray[j];
//								var no = url.indexOf(target);
//								if(no > 0){
//									$scope.dishList[i].imgUrl = url;
//									continue ;
//								}
//							}
						}
					}
					console.log("55555555555555");
				}
			});
			
			
			//头部导航
			$rootScope.pagetitle= "店铺详情";
			$rootScope.next = '<a href="/res/static/index.html#/auth" target="_self"><i class="icon-font" title="我的">&#xe61e;</i></a>';

			//iscroll
			var myScroll;
			$scope.scroll = function(){
				myScroll = new IScroll('#js_scroll', {
					scrollX: true,
					scrollY: false,
					mouseWheel: true,
					scrollbars: true,
					interactiveScrollbars: true,
					shrinkScrollbars: 'scale',
					fadeScrollbars: true
				});
			};

			//当前店铺下的菜品
//			$scope.pageNum =1;
//			$http.post(
//                hpfbase.url+"/shop/dish-list.jhtm",
//                {
//    				dishtype:$scope.currentId ,
//    				shopId:$scope.shopId,
//    				pageNum:$scope.pageNum,
//    				numPerPage:20
//    			}
//			).success(function(ret){
//				if(ret.statusCode){
//					if(!ret.data) return ;
//					$scope.dishList = ret.data.dataList;
//					if ($scope.dishList) {
//						$scope.hasDish = true;
//					};
//				}
//			});

            $scope.shopPhone = "商家电话";
			$scope.hidePhone = function(){
				$scope.showPhone=false;
			}



			//预订
            $scope.booking = function(){
				$scope.showDialog = true;
			}
			//表单
			$scope.forms={
				"datetime":"",
				"number":"",
				"sex":1,
				"name":"",
				"telphone":"",
				"remark":""
			};
           //预订不点菜，先判断是否登录
			$scope.bookNoDish =function(){
				//存储场景
				$window.localStorage.scene = "bookNoDish";
				//定义提交订单，验证登录后执行
				var submitBookNoDish = function(){
					var data="";
					$http.post(
                       hpfbase.url+"XXX",
						data,
						{headers: 
							{'Content-Type': "application/x-www-form-urlencoded;charset=utf-8"}
                        }
					)
					.success(function(ret){
						
					});
				}
				//验证是否登录
				$http.get(hpfbase.url+"/user/isLogin.jhtm")
					.success(function(ret){
						if(ret.succeed){
							submitBookNoDish();
						}else{
							$window.location.href=hpfbase.url+"index.html#/login";
						}
					});
			}
            //预订点菜
			$scope.bookInDish =function(){
				//存储场景
				$window.localStorage.scene = "bookInDish";
				$location.path("/list");
			}
	}]);
//});
